package com.sunny.cloudribbonconsumer;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class HelloService {

    @Autowired
    RestTemplate restTemplate;

    /**
     * 调用提供方的方法
     *
     * 启用hystrix断路器
     *
     * 访问地址 http://127.0.0.1:9200/actuator/hystrix.stream
     * hystrix监控 127.0.0.1:9200/hystrix
     *
     * @param name
     * @return
     */
    @HystrixCommand(fallbackMethod = "error")
    public String hiService(String name) {
        return restTemplate.getForObject("http://CLOUD-EUREKA-CLIENT/hi?name=" + name, String.class);
    }

    public String error(String name) {
        return "hi  " + name + ", error! hystrix start!";
    }

}